package com.ml.service.impl;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import com.ml.enums.EnumPayStatus;
import com.ml.message.OrderSuccessVO;
import com.ml.service.OrderFactory;
import com.ml.service.StateHandler;

@Component
public class UnPaidState implements StateHandler, InitializingBean {

	@Override
	public OrderSuccessVO handler(OrderSuccessVO order) {
		StateHandler stateHandler;
		try {
			// TODO-资金操作
			Boolean isPaid = true;
			order.setAccountId(1000001);
			if (isPaid) {
				stateHandler = OrderFactory.getByOrderState(EnumPayStatus.PAID);
			} else {
				stateHandler = OrderFactory.getByOrderState(EnumPayStatus.FAIL);
			}
		} catch (Exception e) {
			stateHandler = OrderFactory.getByOrderState(EnumPayStatus.ERROR);
			e.printStackTrace();
		}
		return stateHandler.handler(order);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		OrderFactory.register(EnumPayStatus.UNPAID, this);
	}

}
